package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string  `gorm:"type:varchar(30);not null;comment:'用户'"`
	Password string  `gorm:"type:varchar(32);not null;comment:'密码'"`
	Price    float64 `gorm:"type:decimal(10,2);not null;comment:'价格'"`
	Stock    int     `gorm:"type:int(11);not null;comment:'库存'"`
}

func (u *User) UserFindCreate(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).FirstOrCreate(u).Error
}

func (u *User) UserCreate(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UserCreateFind(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) UserList(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}
